package icu.sehnen.progress.controller;

import icu.sehnen.common.result.CommonResult;
import icu.sehnen.progress.entity.Progress;
import icu.sehnen.progress.service.IProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author icu.sehnen
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/progress")
public class ProgressController {
    @Autowired
    IProgressService progressService;
    @GetMapping("/list")
    public CommonResult findAll(){
        List<Progress> progressModelList=progressService.list();
        return  CommonResult.success(progressModelList);
    }

    @GetMapping("/find/{id}")
    public  CommonResult findProgressById(@PathVariable Long id){
        Progress progress=progressService.getById(id);
        return  CommonResult.success(progress);
    }
    @PostMapping("/update")
    public CommonResult update(Progress progress){
        progressService.updateById(progress);
        return  CommonResult.success();
    }
    @PostMapping("/add")
    public CommonResult add(Progress progress){
       Boolean res = progressService.save(progress);
       if(res){
           return  CommonResult.success();
       }
        return CommonResult.failed();
    }
    @PostMapping("/delete/{id}")
    public  CommonResult delete(@PathVariable Long id){
      Boolean res=  progressService.removeById(id);
      if(res){
          return  CommonResult.success();
      }
        return  CommonResult.failed();

    }
}
